#include<iostream>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e6 + 10;
int f1[N], f2[N];
string s;
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> s;
		s = " " + s;
		for (int i = 1; i <= n; i++) {
			f1[i] = f1[i - 1];
			if (s[i] == '0') {
				f1[i] = 0;
				continue;
			}
			f1[i]++;
		}
		for (int i = 1; i <= n; i++) {
			f2[i] = f2[i - 1];
			if (s[i] == '1') {
				f2[i] = 0;
				continue;
			}
			f2[i]++;
		}
		int ma = 0;
		for (int i = 1; i <= n; i++) {
			ma = max(ma, max(f1[i], f2[i]));
		}
		cout << ma << endl;
	}
	return 0;
}